﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BotonJXC.Entity;
using BotonJXC.Util;
using BotonJXC.BLL;

namespace BotonJXC.Forms
{
    public partial class TransferOfFinancialMainForm : BaseMdiForm
    {

        #region 参数
        FinanceBillsBll FinanceBillsBll = null;
        FinanceBills FinanceBills = null;
        //订单
        OrdersBLL OrdersBLL = null;
        //出库
        OutStocksBLL OutStocksBLL = null;
        //入库
        InStocksBll InStocksBll = null;
        //验收
        AcceptanceBll AcceptanceBll = null;
        //调拨
        AllocatesBLL AllocatesBLL = null;
        //退货
        ReturnOrdersBll ReturnOrdersBll = null;
        //
        FinanceBillLogsBll FinanceBillLogsBll = null;
        private Int32 pageSize = 1;
        private Int32 totalSize;
        string[] type;
        #endregion

        #region   初始化
        public TransferOfFinancialMainForm()
        {
            InitializeComponent();
        }
        private void TransferOfFinancialMainForm_Load(object sender, EventArgs e)
        {
            InitStore();
            InitForm();
            LoadDate();
        }
        private void InitForm() {

            type = this.Tag.ToString().Split(',');

            if ("2".Equals(type[0]))
            {
                this.Text = "传财务单";
                this.financialTypeCbox.SelectedIndex = 0;
                financialTypeCbox.Leave += new EventHandler(financialTypeCbox_Leave);
                this.userDataGridView.CellEndEdit += new DataGridViewCellEventHandler(userDataGridView_CellEndEdit);
            }
            else {
                this.DefStroeText.Enabled = false;
                this.DefStroeCbox.Enabled = false;
                this.financialTypeCbox.Enabled = false;
                this.FinaBillSnText.Enabled = false;
                this.remarkText.Enabled = false;
                this.Text = "传财务单处理";
                this.PrintTimeBtn.Visible = false;
                this.addBtn.Visible = false;
                this.deletedBtn.Visible = false;
                this.searchBtn.Visible = false;
                this.saveBtn.Visible = false;
                this.addProductsBtn.Visible = false;
                this.deleteProductBtn.Visible = false;
                this.returnBtn.Visible = false;
                this.cancelBtn.Visible = false;
                this.flowBtn.Visible = false;
                this.userDataGridView.ReadOnly = true;
            }
        
        }

        private void LoadDate()
        {
            FinanceBills FinanceBillsSearch = new FinanceBills();

            if("4".Equals( type[0] )){

                FinanceBillsSearch.AuditStatus = "2";
            }
            
            if (FinanceBillsBll == null) FinanceBillsBll = new FinanceBillsBll();
            PageModel<FinanceBills> pageModel = FinanceBillsBll.FindPage(FinanceBillsSearch, (pageSize - 1) * 1, 1);
            if (pageModel.Results.Count == 0)
            {
                this.deletedBtn.Enabled = false;
                this.auditBtn.Enabled = false;
                this.saveBtn.Enabled = false;
            }
            else
            {

                //赋值
                foreach (FinanceBills financeBills in pageModel.Results)
                {
                    this.FinanceBills = financeBills;
                }

                string AuditStatus = this.FinanceBills.AuditStatus;
                if ("4".Equals(type[0]))
                {
                    AuditStatus = this.FinanceBills.AccOptSign;
                }
            

                //已审核
                if (Utils.ToString((Int32)Status.AuditPass).Equals(AuditStatus))
                {
                    this.deletedBtn.Enabled = false;
                    this.auditBtn.Enabled = false;
                    this.saveBtn.Enabled = false;
                }
                else
                {
                    this.deletedBtn.Enabled = true;
                    this.auditBtn.Enabled = true;
                    this.saveBtn.Enabled = true;
                }

                //分页
                pageBtnControl(pageModel);


                this.FinaBillSnText.Text = this.FinanceBills.FinaBillSn;
                this.SalesmanLabel.Text ="业务员:　"+ this.FinanceBills.Salesman;
                if (this.FinanceBills.DefStore != null) {
                    this.DefStroeText.Text = this.FinanceBills.DefStore.StoreSn;
                    this.DefStroeCbox.Text = this.FinanceBills.DefStore.StoreName;
                }

                if (!"".Equals(this.FinanceBills.BillType))
                {
                    int _BillType = Utils.ToInt(this.FinanceBills.BillType, 0);
                    this.financialTypeCbox.Text = StatusUtil.getOrderTypeName(_BillType);
                    this.financialTypeCbox.Tag = StatusUtil.getOrderTypeName(_BillType);
                }

                if (this.FinanceBills.Account !=null)
                {
                    this.CreateLabel.Text = "制单人:　" + this.FinanceBills.Account.Username;
                }
                this.CreateTimeLabel.Text = "制单时间: " + string.Format("{0:yyyy/MM/dd HH:mm:ss}", this.FinanceBills.CreateTime);
                if (this.FinanceBills.AccountAudit != null)
                {
                    this.AccountAuditLabel.Text = "审核人:　" + this.FinanceBills.AccountAudit.Username;
                }
                this.AuditTimeLabel.Text = "审核日期: " + string.Format("{0:yyyy/MM/dd HH:mm:ss}", this.FinanceBills.AuditTime);

                this.PrintTimeLabel.Text = "打印次数: " + this.FinanceBills.PrintTime;

                
              
                if ("2".Equals(type[0]))
                {
                    this.StatusLabel.Text = "单据状态:　" + StatusUtil.getAuditString(Utils.ToInt(this.FinanceBills.AuditStatus, 1));
                    this.remarkText.Text = this.FinanceBills.Remark;
                    this.auditRemarkText.Text = this.FinanceBills.AuditRemark;
                }
                else {
                    this.StatusLabel.Text = "单据状态:　" + StatusUtil.getAuditString(Utils.ToInt(this.FinanceBills.AccountAccOpt, 1));
                    this.auditRemarkText.Text = this.FinanceBills.AccOptRemark;
                    this.remarkText.Text = this.FinanceBills.AuditRemark;
                }
                userDataGridView.Rows.Clear();
                foreach (FinanceBillsLogs FinanceBillsLogs in this.FinanceBills.FinanceBillsLogsList) {
                    int index = this.userDataGridView.Rows.Add();
                    this.userDataGridView["BillSn", index].Value = FinanceBillsLogs.BillSn;
                    this.userDataGridView["BillAuditTime", index].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", FinanceBillsLogs.BillAuditTime);
                    this.userDataGridView["OrderType", index].Value = StatusUtil.getOrderTypeName( Utils.ToInt( this.FinanceBills.BillType,0)); ;
                    if ("2".Equals(type[0]))
                    {
                        this.userDataGridView["BillSign", index].Value = Utils.ToString((Int32)Status.AuditPass).Equals(this.FinanceBills.AuditStatus) ? "已传" : "未传";
                    }
                    else {
                        this.userDataGridView["BillSign", index].Value = Utils.ToString((Int32)Status.AuditPass).Equals(this.FinanceBills.AccOptSign)   ?  "已接":"未接" ;
                    }
                    this.userDataGridView["InputSeq", index].Value = FinanceBillsLogs.InputSeq;
                }
            }
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pageModel"></param>
        private void pageBtnControl(PageModel<FinanceBills> pageModel)
        {
            this.totalSize = pageModel.PageCount;

            if (pageSize == totalSize)
            {
                this.next.Enabled = false;
            }
            else
            {
                this.next.Enabled = true;
            }
            if (pageSize == 1)
            {
                this.up.Enabled = false;
            }
            else
            {
                this.up.Enabled = true;
            }
        }

        /// <summary>
        /// 初始化分店下拉框
        /// </summary>
        private void InitStore()
        {
            StoreBLL StoreBLL = new StoreBLL();
            this.DefStroeCbox.DataSource = StoreBLL.FindAll();
            DefStroeCbox.DisplayMember = "StoreName";//显示字段
            DefStroeCbox.ValueMember = "StoreId";//id值
            
        }

        #endregion

        #region 公用方法
        /// <summary>
        /// 获取财务单
        /// </summary>
        /// <returns></returns>
        private FinanceBills getFinanceBills() {

            FinanceBills _FinanceBills = null;
            if ("add".Equals(this.saveBtn.Tag))
            {
                _FinanceBills = new FinanceBills();
                _FinanceBills.Account = LoginForm.Account;
                _FinanceBills.CreateTime = DateTime.Now;
                _FinanceBills.AuditStatus = Utils.ToString((Int32)Status.None);
                _FinanceBills.FinaBillSn = new BillSNGenerator().GeneratorBillSn(BillType.Return, BillSource.DistributionCenter, LoginForm.StoreId);
                _FinanceBills.DefStore = (Store)this.DefStroeCbox.SelectedItem;
                _FinanceBills.Remark = this.remarkText.Text;
                _FinanceBills.Salesman = "";
                Dictionary<string, object> myDic = StatusUtil.getOrderType( this.financialTypeCbox.Text );
                _FinanceBills.BillType = myDic["OrderCode"].ToString();
            }
            else {
                _FinanceBills = this.FinanceBills;
                _FinanceBills.Salesman = LoginForm.Account.Username;
            }
            _FinanceBills.FinanceBillsLogsList = getFinanceBillsLogs();

            return _FinanceBills;
        }


        private IList<FinanceBillsLogs> getFinanceBillsLogs() {
           IList<FinanceBillsLogs> FinanceBillsLogsList = new List<FinanceBillsLogs>() ;
           Dictionary<string, object> myDic = null;
           int InputSeq = 0;
            for (int i = 0; i < this.userDataGridView.Rows.Count - 1; i++)//如果DataGridView中有空的数据，则提示数据输入不完整并退出添加，不包括标题行
            {
                FinanceBillsLogs FinanceBillsLogs = new FinanceBillsLogs();
                FinanceBillsLogs.BillSn = userDataGridView["BillSn", i].Value.ToString();
                FinanceBillsLogs.BillSign =Utils.ToInt(userDataGridView["BillSign", i].Value ,0);
                myDic =  StatusUtil.getOrderType(userDataGridView["OrderType", i].Value.ToString());
                FinanceBillsLogs.BillType =  myDic["OrderCode"].ToString();
                FinanceBillsLogs.BillAuditTime = Convert.ToDateTime(userDataGridView["BillAuditTime", i].Value);
                
                FinanceBillsLogs.BillSign = 1;
               
              
                if (!"已传".Equals(userDataGridView["BillSign", i].Value.ToString()))
                {
                    FinanceBillsLogs.InputSeq = InputSeq + 1;
                    InputSeq += 1;
                    FinanceBillsLogsList.Add(FinanceBillsLogs);
                }
               
            }

            return FinanceBillsLogsList;
        }

        private void returnInit() {

                userDataGridView.Rows.Clear();
                this.FinaBillSnText.Text = "";
                this.DefStroeText.Text = "";
                this.DefStroeCbox.SelectedIndex = 0;
                this.financialTypeCbox.SelectedIndex = 0;

                this.CreateLabel.Text = "制单人: ";
                this.CreateTimeLabel.Text = "制单日期:　";
                this.PrintTimeLabel.Text = "打印次数: ";
                this.StatusLabel.Text = "单据状态:　";
                this.AccountAuditLabel.Text = "审核人: ";
                this.AuditTimeLabel.Text = "审核日期: ";
                this.remarkText.Text = "";

                this.SalesmanLabel.Text = "业务员:";
            }

        #endregion

        #region 控件事件
        private void addBtn_Click(object sender, EventArgs e)
        {
            this.saveBtn.Tag = "add";
            this.deletedBtn.Enabled = false;
            this.saveBtn.Enabled = true;
         
            returnInit();
        }

        private void deletedBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认要删除当前出库订单吗？", "删除确认",
        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)

                if (FinanceBillsBll == null) FinanceBillsBll = new FinanceBillsBll();
            bool result = FinanceBillsBll.DeleteFinance(FinanceBills);
            if (result)
            {
                MessageBox.Show("单据删除成功!");
                LoadDate();
            }
            else
            {
                MessageBox.Show("单据删除失败!");
            }

        }

        private void auditBtn_Click(object sender, EventArgs e)
        {
            if ("4".Equals(type[0]))
            {
                this.FinanceBills.AccOptSign = Utils.ToString((Int32)Status.AuditPass);
                this.FinanceBills.AccOptTime = DateTime.Now;
                this.FinanceBills.AccOptRemark = this.auditRemarkText.Text;
                
            }
            else {
                this.FinanceBills.AuditStatus = Utils.ToString((Int32)Status.AuditPass);
                this.FinanceBills.AuditTime = DateTime.Now;
                this.FinanceBills.AuditRemark = this.auditRemarkText.Text;
            }
            foreach (FinanceBillsLogs _financeBillsLogs in FinanceBills.FinanceBillsLogsList)
            {

                if (this.FinanceBillLogsBll == null) { FinanceBillLogsBll = new FinanceBillLogsBll(); }
                FinanceBillsLogs FinanceBillsLogs = FinanceBillLogsBll.findFinanceBillsLogsBySn(_financeBillsLogs.BillSn, _financeBillsLogs.BillType,2);
                if (FinanceBillsLogs == null)
                {
                    _financeBillsLogs.BillSign = Utils.ToInt(type[0], 2);
                }
                else {

                    MessageBox.Show("单据编号: " + _financeBillsLogs.BillSn +
                        " 单据类型: " + StatusUtil.getOrderTypeName(Utils.ToInt(_financeBillsLogs.BillType,0))
                        + " 在其他财务单中的标志为: " + StatusUtil.getFinanceBillsLogsSign(FinanceBillsLogs.BillSign) + ",请删除后再审核!");
                    return;
                }

            }


            this.FinanceBills.AccountAudit = LoginForm.Account;
     

            if (FinanceBillsBll == null) FinanceBillsBll = new FinanceBillsBll();
            bool result = FinanceBillsBll.Modify(FinanceBills);
            if (result)
            {
                MessageBox.Show("单据审核成功!");
                LoadDate();
            }
            else
            {
                MessageBox.Show("单据删除失败!");
            }
        }

        private void deleteProductBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认要删除该行数据吗？", "删除确认",
             MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                // 确定 删除
                foreach (DataGridViewRow r in userDataGridView.SelectedRows)
                {
                    if (!r.IsNewRow)
                    {
                        userDataGridView.Rows.Remove(r);
                    }
                }
            }
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (this.FinanceBillsBll == null) this.FinanceBillsBll = new FinanceBillsBll();

            if ("add".Equals(this.saveBtn.Tag))
            {

                bool result = FinanceBillsBll.SaveFinance(getFinanceBills());
                if (result)
                {
                    MessageBox.Show("单据添加成功!");
                    LoadDate();
                    this.saveBtn.Tag = "up";
                    this.saveBtn.Enabled = true;
                }
                else
                {
                    MessageBox.Show("单据添加失败!");
                }
            }
            else if ("up".Equals(this.saveBtn.Tag))
            {
                bool result = FinanceBillsBll.Modify(getFinanceBills());
                if (result)
                {
                    MessageBox.Show("单据修改成功!");
                    
                }
                else
                {
                    MessageBox.Show("单据修改失败!");
                }
            }
        }

        private void next_Click(object sender, EventArgs e)
        {
            pageSize = pageSize + 1;
            LoadDate();
        }

        private void up_Click(object sender, EventArgs e)
        {
            pageSize = pageSize - 1;
            LoadDate();
        }

        private void userDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            dataGridViewCellEndEdit(e.ColumnIndex, e.RowIndex);
        }

        private void dataGridViewCellEndEdit(int ColumnIndex, int RowIndex)
        {
            string parameter = userDataGridView.Columns[ColumnIndex].Name;
            if ("BillSn".Equals(parameter) || "OrderType".Equals(parameter))
            {
                string orderSn = userDataGridView["BillSn", RowIndex].Value == null ? "" : userDataGridView["BillSn", RowIndex].Value.ToString();
                string orderType = financialTypeCbox.Text;
                if ("".Equals(orderType) || "请选择".Equals(orderType))
                {
                    orderType = userDataGridView["OrderType", RowIndex].Value == null ? "" : userDataGridView["OrderType", RowIndex].Value.ToString();
                }


                if (!"".Equals(orderSn))
                {
                    if (!"".Equals(orderType) && !"请选择".Equals(orderType))
                    {
                             Dictionary<string, object> myDic = StatusUtil.getOrderType(orderType);
                             int orderTypeNum = Utils.ToInt(myDic["OrderCode"], 0);
                             string CreatePlace =  myDic["CreatePlace"].ToString();
                             string _OrderType = myDic["OrderType"].ToString();
                        if (1 <= orderTypeNum && orderTypeNum <= 4)
                        {
                            //订单查询
                            if (this.OrdersBLL == null) { OrdersBLL = new OrdersBLL(); }
                            Orders _order = OrdersBLL.findOrdersBySn(orderSn, _OrderType.ToString());
                            if (_order != null)
                            {
                                if (_order.AuditStatus.Equals(Utils.ToString((Int32)Status.AuditPass)))
                                {
                                    userDataGridView["OrderType", RowIndex].Value = orderType;
                                    userDataGridView["BillAuditTime", RowIndex].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", _order.AuditTime);
                                }
                                else
                                {
                                    userDataGridView["BillSn", RowIndex].Value = "";
                                    MessageBox.Show("订单尚未审核");
                                    return;
                                }
                            }
                            else
                            {
                                userDataGridView["BillSn", RowIndex].Value = "";
                                MessageBox.Show("订单编号有误或与单据类型不匹配");
                                return;
                            }
                        }
                        else if (5 <= orderTypeNum && orderTypeNum <= 10)
                        {
                            //出库单查询
                            if (this.OutStocksBLL == null) { OutStocksBLL = new OutStocksBLL(); }

                            OutStocks _OutStocks = OutStocksBLL.findOutStocksBySn(orderSn, _OrderType, CreatePlace);

                            if (_OutStocks != null)
                            {
                                if (_OutStocks.AuditStatus.Equals(Utils.ToString((Int32)Status.AuditPass)))
                                {
                                    userDataGridView["OrderType", RowIndex].Value = orderType;
                                    userDataGridView["BillAuditTime", RowIndex].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", _OutStocks.AuditTime);
                                }
                                else
                                {
                                    userDataGridView["BillSn", RowIndex].Value = "";
                                    MessageBox.Show("订单尚未审核");
                                    return;
                                }
                            }
                            else
                            {
                                userDataGridView["BillSn", RowIndex].Value = "";
                                MessageBox.Show("订单编号有误或与单据类型不匹配");
                                return;
                            }
                        }
                        else if (11 <= orderTypeNum && orderTypeNum <= 13)
                        {
                            //入库单查询
                            if (this.InStocksBll == null) { InStocksBll = new InStocksBll(); }
                            InStocks _InStocks = InStocksBll.findInStocksBySn(orderSn, CreatePlace);
                            if (_InStocks != null)
                            {
                                if (_InStocks.AuditStatus.Equals(Utils.ToString((Int32)Status.AuditPass)))
                                {
                                    userDataGridView["OrderType", RowIndex].Value = orderType;
                                    userDataGridView["BillAuditTime", RowIndex].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", _InStocks.AuditTime);
                                }
                                else
                                {
                                    userDataGridView["BillSn", RowIndex].Value = "";
                                    MessageBox.Show("订单尚未审核");
                                    return;
                                }
                            }
                            else
                            {
                                userDataGridView["BillSn", RowIndex].Value = "";
                                MessageBox.Show("订单编号有误或与单据类型不匹配");
                                return;
                            }
                        }
                        else if (14 <= orderTypeNum && orderTypeNum <= 18)
                        {
                            //调拨单查询
                            if (this.AllocatesBLL == null) { AllocatesBLL = new AllocatesBLL(); }
                            Allocates _Allocates = AllocatesBLL.findAllocatesBySn(orderSn, _OrderType);
                            if (_Allocates != null)
                            {
                                if (_Allocates.AuditStatus.Equals(Utils.ToString((Int32)Status.AuditPass)))
                                {
                                    userDataGridView["OrderType", RowIndex].Value = orderType;
                                    userDataGridView["BillAuditTime", RowIndex].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", _Allocates.AuditTime);
                                }
                                else
                                {
                                    userDataGridView["BillSn", RowIndex].Value = "";
                                    MessageBox.Show("订单尚未审核");
                                    return;
                                }
                            }
                            else
                            {

                                userDataGridView["BillSn", RowIndex].Value = "";
                                MessageBox.Show("订单编号有误或与单据类型不匹配");
                                return;
                            }
                        }
                        else if (19 <= orderTypeNum && orderTypeNum <= 21)
                        {
                            //验收单查询
                            if (this.AcceptanceBll == null) { AcceptanceBll = new AcceptanceBll(); }
                            Acceptance _Acceptance = AcceptanceBll.findAcceptanceBySn(orderSn, _OrderType);
                            if (_Acceptance != null)
                            {
                                if (_Acceptance.AuditStatus.Equals(Utils.ToString((Int32)Status.AuditPass)))
                                {
                                    userDataGridView["OrderType", RowIndex].Value = orderType;
                                    userDataGridView["BillAuditTime", RowIndex].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", _Acceptance.AuditTime);
                                }
                                else
                                {
                                    userDataGridView["BillSn", RowIndex].Value = "";
                                    MessageBox.Show("订单尚未审核");
                                    return;
                                }
                            }
                            else
                            {
                                userDataGridView["BillSn", RowIndex].Value = "";
                                MessageBox.Show("订单编号有误或与单据类型不匹配");
                                return;
                            }
                        }
                        else if (orderTypeNum == 22)
                        {
                            //退货单
                            if (this.ReturnOrdersBll == null) { ReturnOrdersBll = new ReturnOrdersBll(); }
                            ReturnedBlls _ReturnedBlls = ReturnOrdersBll.findReturnedBllsBySn(orderSn);
                            if (_ReturnedBlls != null)
                            {
                                if (_ReturnedBlls.AuditStatus.Equals(Utils.ToString((Int32)Status.AuditPass)))
                                {
                                    userDataGridView["OrderType", RowIndex].Value = orderType;
                                    userDataGridView["BillAuditTime", RowIndex].Value = string.Format("{0:yyyy/MM/dd HH:mm:ss}", _ReturnedBlls.AuditTime);
                                }
                                else
                                {
                                    userDataGridView["BillSn", RowIndex].Value = "";
                                    MessageBox.Show("订单尚未审核");
                                    return;
                                }
                            }
                            else
                            {
                                userDataGridView["BillSn", RowIndex].Value = "";
                                MessageBox.Show("订单编号有误或与单据类型不匹配");
                                return;
                            }
                        }
                        if (this.type[0].Equals("2"))
                        {
                            //标志查询
                            if (this.FinanceBillLogsBll == null) { FinanceBillLogsBll = new FinanceBillLogsBll(); }
                            FinanceBillsLogs FinanceBillsLogs = FinanceBillLogsBll.findFinanceBillsLogsBySn(orderSn, myDic["OrderCode"].ToString());
                            if (FinanceBillsLogs != null)
                            {
                                userDataGridView["BillSign", RowIndex].Value =StatusUtil.getFinanceBillsLogsSign( FinanceBillsLogs.BillSign );
                            }
                            else
                            {
                                userDataGridView["BillSign", RowIndex].Value = "未传";
                            }
                        }
                    }
                    else
                    {

                        MessageBox.Show("请选择单据类型!");
                    }
                }
            }
        }


        //
        private void financialTypeCbox_Leave(object sender, EventArgs e)
        {
    

            if ("请选择".Equals(financialTypeCbox.Text))
            {
                userDataGridView.Columns["OrderType"].ReadOnly = false;
            }
            else {

                int count = userDataGridView.Rows.Count - 1;
                if (count != 0)
                {
                    // 删除前的用户确认。 
                    if (MessageBox.Show("修改单据类型会导致表格数据清空,确认要重新填写数据吗?", "操作提示",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {

                        userDataGridView.Rows.Clear();
                        financialTypeCbox.Tag = financialTypeCbox.Text;
                    }
                    else
                    {

                        financialTypeCbox.Text = financialTypeCbox.Tag.ToString();
                    }
                }
                else {
                    financialTypeCbox.Tag = financialTypeCbox.Text;
                }
                userDataGridView.Columns["OrderType"].ReadOnly = true;

                //userDataGridView.Columns["OrderType"].c
            }
           
            //userDataGridView.ReadOnly = true;
        }
    

        private void DefStroeCbox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Store Store = (Store)this.DefStroeCbox.SelectedItem;//获取当前选项
            DefStroeText.Text = Store.StoreSn;
        }

        #endregion
    }
}
